package com.morehair.controller.admin;

import com.morehair.bean.vo.admin.BaseRespVo;
import com.morehair.bean.vo.admin.Info;
import com.morehair.bean.bo.LoginUser;
import com.morehair.service.admin.AuthService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.Serializable;

/**
 * @Description:
 * @Author raohui
 * @Date 2021/6/4 13:22
 */
@Controller
@RequestMapping("admin")
@ResponseBody
public class AuthController {
    @Autowired
    AuthService authService;

    @RequestMapping("auth/login")
    public BaseRespVo login(@RequestBody LoginUser user) { //接收json数据
       BaseRespVo baseRespVo=authService.login(user);
       return baseRespVo;
    }



    @RequestMapping("auth/info")
    public BaseRespVo info(String token){
        Info info=authService.getInfo(token);
//        Serializable id = SecurityUtils.getSubject().getSession().getId();
//        System.out.println(id);
        return BaseRespVo.ok(info);
    }


    @RequestMapping("auth/logout")
    public BaseRespVo logout(String token){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return BaseRespVo.ok();
    }

    @RequestMapping("auth/index")
    public BaseRespVo index() {
        return BaseRespVo.fail(501,null,"不登录别想进去");
    }

    @RequestMapping("auth/unAuth")
    public BaseRespVo unAuth() {
        return BaseRespVo.fail(506,null,"你权限不够");
    }

}
